<?php
require_once("Database.php");
require_once("Mail.php");

/**
 * Handles messages in the 'about' section.
 * 
 * @author Magnus Stoveland <mstoveland@gmail.com>
 */
class Message
{
    /**
     * Fetch table values from db.
     * 
     * @return array $venues
     */   
    function getModel() {
	    $query = "SELECT * FROM messages ORDER BY timestamp";
	    $db = Database::getInstance();
		$result = $db->query($query);
	    while($row = mysql_fetch_array($result)) {
            $venues[] = $row;
	   }
	   return $venues;
   }
   
   /**
    * Store a new message in db. 
    * 
    * @param string $name
    * @param string $message
    */
   function store($name, $message) {
	    $query = "INSERT INTO messages (name, message, timestamp) VALUES ('".$name."', '".$message."', now())"; 
	    $db = Database::getInstance();
		$result = $db->query($query);
		//Send notification mail to administrators
		$message = "A new message has been posted by ".$name."\n\n\"".$message."\"";
		Mail::sendNotification("New message", $message);
   }
}
?>